package java网络编程;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

/**
 * @author coderFu
 * @create 2022/2/25
 * UDP 用户数据报协议
 */
public class Receiver {

    public static void main(String[] args) throws IOException {

        // 创建接收端对象
        DatagramSocket receive = new DatagramSocket(10010);

        byte[] buffer = new byte[1024];

        //接收数据
        DatagramPacket datagramPacket = new DatagramPacket(buffer, 1024);


        receive.receive(datagramPacket);

        String mString = new String(datagramPacket.getData(), 0, datagramPacket.getLength());

        System.out.println("Sender 发送者发送来的数据： "+ mString);
    }
}
